function getElement(id) { return document.getElementById(id); }

function update(id) {
    var curr = getElement(id);
    var coA = getElement('coA');
    var coB = getElement('coB');
    var coC = getElement('coC');
    
    if (curr.selectedIndex === 0) {
        if (curr == coA) {
            coB.selectedIndex = coC.selectedIndex = 1;
        } else if (curr == coB) {
            coA.selectedIndex = coC.selectedIndex = 1;
        } else if (curr == coC) {
            coA.selectedIndex = coB.selectedIndex = 1;
        }
    }
}

function update2(id) {
    var curr = getElement(id);
    var coV = getElement('coV');
    var coF = getElement('coF');
    
    if (curr.selectedIndex === 0) {
        if (curr == coF) {
            coV.selectedIndex = 1;
        } else {
            coF.selectedIndex = 1;
        }
    }
}

function updateExamenes() {
    var check = document.getElementsByTagName('input');
    var blah = getElement('examen');
    var text = "";
    
    for (var i = 0; i < check.length; i++) {
        if (check[i].type != "checkbox") {
          continue;
        }
        
        if (check[i].checked) {
            text += check[i].value + "|";
        }
    }
    
    blah.value = text;
}

function juntaRespuestas() {
    var check = document.getElementsByTagName('input');
    var blahM = getElement('multiple');
    var blahV = getElement('vf');
    var blahR = getElement('relacionar');
    var blahA = getElement('abierta');
    
    var reM = /multiple-(\d+)/;
    var reV = /vf-(\d+)/;
    var reR = /relacionar-(\d+)/;
    var reA = /abierta-(\d+)/;

    var textM = "";
    var textV = "";
    var textR = "";
    var textA = "";
    
    for (var i = 0; i < check.length; i++) {
        if (check[i].type != "radio" && check[i].type != "text") {
          continue;
        }
        
        var mM = reM.exec(check[i].name);
        var mV = reV.exec(check[i].name);
        var mR = reR.exec(check[i].name);
        var mA = reA.exec(check[i].name);
        
        if (check[i].type == "radio" && check[i].checked) {
            if (mM !== null) {
              textM += mM[1] + "-" + check[i].value + "|";
            } else if (mV !== null) {
              textV += mV[1] + "-" + check[i].value + "|";
            }
        } else if (check[i].type == "text") {
            if (mR !== null) {
              textR += mR[1] + "-" + check[i].value + "|";
            } else if (mA !== null) {
              textA += mA[1] + "-" + check[i].value + "|"; 
            }
        }
    }
    
    blahM.value = textM;
    blahV.value = textV;
    blahR.value = textR;
    blahA.value = textA;
}